import os
import numpy as np
import pandas as pd
import os
import time
import glob
import re
import warnings
from program.pack.append_df_to_excel import append_df_to_excel
from pandas import to_datetime
from functools import reduce

warnings.filterwarnings("ignore")

# 列显示不全，进行设置
pd.set_option('display.max_columns', 500)
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
pd.set_option('display.width', 180)  # 设置打印宽度(**重要**)

path = r'W:\wangshuan\TAI40-II\zc\2022-01-11\2022-01-11-2#-jichang-9'
# originImage
# detectImage
sub_dirs = os.listdir(path + '\\originImage')
# 仅读取时间戳  对时间戳进行正序排序
sub_dirs = [int(str(x).split('_')[-1]) for x in sub_dirs]
sub_dirs = sorted(sub_dirs)
print(sub_dirs)

file_txt = 'label_dhq_ok.txt'
file_name = os.path.join(path, file_txt)  # txt 文件地址
file_txt = open(file_name, "r", encoding='UTF-8').read()  # 读取txt,encoding = 'utf-8').read()
# print(file_txt)
# file_txt.close()
for i in range(len(sub_dirs)):
    file = path + '\\originImage' + '\\' + str(sub_dirs[i])
    file_new = path + '\\originImage' + '\\' + str(i + 1) + '_' + str(sub_dirs[i])
    # print(file)
    # print(file_new)
    old = str(sub_dirs[i])
    new = str(i + 1) + '_' + str(sub_dirs[i])
    file_txt = file_txt.replace(old, new)

    try:
        if os.path.isdir(file):
            os.rename(file, file_new)
            print('1', file_new)
        else:
            os.rename(file, file_new)
            print('2', file, file_new)
    except Exception as e:
        print(file_new, e)
print(file_txt)



